package com.bestcem.xm.ticket.service.manager.role;

import com.bestcem.xm.ticket.entity.mongo.TicketFlow;
import com.bestcem.xm.ticket.enums.FollowerFilterEnum;
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;
import java.util.Objects;

/**
 * 工单规则 跟进人 信息工具类
 * 工单跟进者配置
 * 工单最多配置两个跟进者(角色), 两个任意一个完成跟进,工单进入下一状态
 * 两个跟进者是平行的关系.
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/17 20:14
 */
@ToString(callSuper = true)
@Getter
public class TicketFollower extends BaseTicketRole {
    /**
     * 工单系统关闭
     */
    public static final Integer SYSTEM_CLOSE = 0;
    /**
     * 工单转移到第二跟进人
     */
    public static final Integer TRANSFER_SECOND_FOLLOWER = 1;
    /**
     * 工单继续跟进
     */
    public static final Integer KEEP_FOLLOW = 2;

    /**
     * 转派给超级管理员
     */
    public static final Integer SUBMIT_SUPER_ADMIN = 3;


    /**
     * 逾期处理逻辑，0-系统关闭工单，1-保持跟进，2-工单转移给第二跟进人
     */
    private Integer overdueHandle;
    /**
     * emptyFollowerHandle
     */
    private Integer emptyFollowerHandle;
    /**
     * followerFilter
     */
    private FollowerFilterEnum followerFilter;
    /**
     * followerId
     */
    private String followerId;


    private TicketFollower(TicketFlow.FollowConfig followConfig) {
        super(followConfig);
        if (Objects.isNull(followConfig)) {
            return;
        }
        this.overdueHandle = followConfig.getOverdueHandle();
        this.emptyFollowerHandle = followConfig.getEmptyFollowerHandle();
        this.followerFilter = FollowerFilterEnum.getByIndex(followConfig.getFollowerFilter());
        this.followerId = followConfig.getFollowerId();
    }

    /**
     * 构建实例
     *
     * @param followConfig 入参
     * @return 实例
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/20 16:01
     */
    @Nullable
    public static TicketFollower getInstance(TicketFlow.FollowConfig followConfig) {
        if (Objects.isNull(followConfig)) {
            return null;
        }
        return new TicketFollower(followConfig);
    }
}
